import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  // 首页
  {
    path: "/home",
    name: "Home",
    component: () => import("../views/home/index.vue"),
  },
  // 首页定位
  {
    path: "/home/location",
    name: "Location",
    component: () => import("../views/home/location/index.vue"),
    meta: {
      title: "定位",
    },
  },
  // 首页搜索
  {
    path: "/home/search",
    name: "search",
    component: () => import("../views/home/search/index.vue"),
    meta: {
      title: "商品搜索",
    },
  },
  // 制造商列表页
  {
    path: "/home/brand",
    name: "brand",
    meta: {
      title: "制造商",
    },
    component: () => import("../views/home/brand/index.vue"),
  },
  // 制造商详情
  {
    path: "/home/brand/branddetail",
    name: "branddetail",
    meta: {
      title: "制造商详情",
    },
    component: () => import("../views/home/brand/branddetail/index.vue"),
  },
  // 商品列表页
  {
    path: "/goods",
    name: "Goods",
    component: () => import("../views/goods/index.vue"),
    meta: {
      title: "商品列表",
    },
  },
  // 商品列表页
  {
    path: "/goods/goodsdetail",
    name: "GoodsDetail",
    component: () => import("../views/goods/goodsdetail/index.vue"),
    meta: {
      title: "商品详情",
    },
  },
  // 专题
  {
    path: "/topic",
    name: "Topic",
    component: () => import("../views/topic/index.vue"),
  },
  // 专题详情页
  {
    path: "/topic/topicdetail",
    name: "TopicDetail",
    component: () => import("../views/topic/topicdetail/index.vue"),
    meta: {
      title: "专题详情",
    },
  },
  // 分类
  {
    path: "/category",
    name: "Category",
    component: () => import("../views/category/index.vue"),
  },
  // 分类列表
  {
    path: "/category/categorylist",
    name: "CategoryList",
    component: () => import("../views/category/categorylist/index.vue"),
    meta: {
      title: "分类列表",
    },
  },
  // 购物车
  {
    path: "/cart",
    name: "Cart",
    component: () => import("../views/cart/index.vue"),
  },
  // 购物车订单确认
  {
    path: "/cart/orderconfirm",
    name: "orderconfirm",
    meta: {
      title: "支付",
    },
    component: () => import("../views/cart/orderconfirm/index.vue"),
  },
  //我的
  {
    path: "/mine",
    name: "Mine",
    component: () => import("../views/mine/index.vue"),
  },
  // 意见反馈
  {
    path: "/mine/feedback",
    name: "feedback",
    meta: {
      title: "反馈",
    },
    component: () => import("../views/mine/feedback/index.vue"),
  },
  // 我的收藏
  {
    path: "/mine/collect",
    name: "collect",
    meta: {
      title: "我的收藏",
    },
    component: () => import("../views/mine/collect/index.vue"),
  },
  // 地址管理
  {
    path: "/addressmanage",
    name: "addressmanage",
    meta: {
      title: "我的地址",
    },
    component: () => import("../views/addressmanage/index.vue"),
  },
  // 新增地址&编辑地址
  {
    path: "/addressmanage/editaddress",
    name: "editaddress",
    meta: {
      title: "新建地址",
    },
    component: () => import("../views/addressmanage/editaddress/index.vue"),
    beforeEnter(to, from, next) {
      to.meta.title = to.query.id ? "编辑地址" : "新建地址";
      next();
    },
  },
];

const router = new VueRouter({
  routes,
});

export default router;
